/****************************************************** 
 *	Code by Utkarsh Sinha
 *	Based on JIFT by Jun Liu
 *	Visit http://aishack.in/ for more indepth articles and tutorials
 *	on artificial intelligence
 * Use, reuse, modify, hack, kick. Do whatever you want with
 * this code :)
 ******************************************************/

#ifndef DESCRIPTOR_H
#define DESCRIPTOR_H

using namespace std;
class Descriptor
{
public:
	float			xi, yi;		// The location
	vector<double>	fv;			// The feature vector

	Descriptor()
	{
	}

	Descriptor(float x, float y, vector<double> const& f)
	{
		xi = x;
		yi = y;
		fv = f;
	}

	// verifica se os
	//int match(Descriptor other);
	// calcula a medida euclidiana entre os features vectors
	double descriptorEuclideanDistance(Descriptor *other)
	{
		double result = 0;
		for (int i = 0; i < fv.size(); ++ i) {

			double valor1 = other->fv[i];
			double valor2 = fv[i];

			if (isnan(valor1)) valor1= 0;
			if (isnan(valor2)) valor2= 0;

			double diferenca = valor1 - valor2;
			result += diferenca*diferenca;
			/*if (isnan(result))
				printf("\n\t%f - %f = %f <> %f",valor1,valor2,diferenca,valor1 - valor2);*/
			//printf(" result:[%f] ",result);
		};

		return (result);
	}

	// calcula a distancia entre os pontos dos descritores
	double EuclideanDistanceBetweenDescriptors(Descriptor *other)
	{
		double result = 0;
		double deltax;
		double deltay;

		double valor1;
		double valor2;
		double valor3;
		double valor4;


		if (isnan(other->xi)) valor1 = 0; else valor1 = other->xi;
		if (isnan(xi)) valor2 = 0; else valor2 = xi;

		deltax = valor2 - valor1;

		if (isnan(other->yi)) valor3 = 0; else valor3 = other->yi;
		if (isnan(yi)) valor4 = 0; else valor4 = yi;

		deltay = valor4 - valor3;

		// calculando a distancia euclidiana
		result = sqrt(deltax*deltax + deltay*deltay);

		return (result);
	}

	void debug()
	{
		printf("Desc(%f,%f,",xi,yi);
		/*for (int i = 0; i < fv.size(); ++ i) {
			printf(" [%f] ",fv[i]);
		};*/

		printf(")\n");
	}

};

#endif
